// 订单管理相关API
import { axiosInstance } from './request'

const orderAPI = {
  // 创建订单
  createOrder(data) {
    return axiosInstance({
      url: '/orders',
      method: 'post',
      data,
    })
  },
  // 获取订单详情
  getOrder(id) {
    return axiosInstance({
      url: `/orders/${id}`,
      method: 'get',
    })
  },
  // 获取我的租户订单
  getMyTenantOrders(params) {
    return axiosInstance({
      url: '/orders/my/tenant',
      method: 'get',
      params,
    })
  },
  // 获取我的出租方订单
  getMyLessorOrders(params) {
    return axiosInstance({
      url: '/orders/my/lessor',
      method: 'get',
      params,
    })
  },
  // 租赁方完成订单
  setCompleteOrder(id) {
    return axiosInstance({
      url: `/orders/${id}/complete`,
      method: 'post',
    })
  },
  // 出租方确认订单
  setConfirmOrder(id) {
    return axiosInstance({
      url: `/orders/${id}/confirm`,
      method: 'post',
    })
  },
  // 获取最新订单（当前用户作为租赁方 & 指定账号）
  getLatestOrderByAccount(accountId) {
    return axiosInstance({
      url: '/orders/latest',
      method: 'get',
      params: { accountId },
    })
  },
  
  // 退款订单
  refundOrder(id, data) {
    return axiosInstance({
      url: `/orders/${id}/refund`,
      method: 'post',
      data,
    })
  }
}

// 导出整个 API 对象
export default orderAPI